package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.SetMeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.Setmeal;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from sky_take_out.setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    Integer checkDishByIds(List<Long> ids);

    List<Setmeal> query(SetmealPageQueryDTO dto);

    @AutoFill(OperationType.INSERT)
    void addSetmeal(SetMeal setMeal);

    void deleteAll(List<Long> ids);

    Integer checkStatus(List<Long> ids);

    @Select("select s.* , c.name as categoryName from sky_take_out.setmeal s left join sky_take_out.category c on c.id = s.category_id where s.id = #{id}")
    Setmeal queryById(Long id);

    void updateSetmeal(Setmeal setmeal);

    @Update("update sky_take_out.setmeal set status = #{status} where id = #{id}")
    void updateSetmealStauts(Integer status, Long id);

    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from sky_take_out.setmeal_dish sd left join sky_take_out.dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);
}
